home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 283_01 / vidinit.c < prev    next >
C/C++ Source or Header  |  1988-12-14  |  6KB  |  178 lines

  1. /* vidinit.c -- 9/5/88, d.c.oshel
  2.  
  3.    This is the part of CIAO that contains initialization and deinitialization,
  4.    plus all global and external data.  There are no references to functions
  5.    other than the C library and the MSJ low-level I/O function in here.
  6.    */
  7.  
  8. #include "vidinit.h"
  9.  
  10. /*
  11. ** globals
  12. */
  13.  
  14. /* struct MSJ_VideoInfo video; <-- this is in LVIDEO.OBJ */
  15.  
  16. int vid[16] =  /* vid_init() changes this table if cga */
  17. {
  18.     NRM, BRN, RVR, BLR, 
  19.     UNL, BRU, BLN, BLU, 
  20.     BBN, BBU, NRM, NRM,
  21.     NRM, NRM, NRM, NRM
  22. };
  23.  
  24. int rasterh  = 12, rasterl  = 13;  /* monochrome cursor default raster lines */
  25.  
  26. int vid_attr = 7,           /* HEAVILY USED HEREIN */
  27.     vid_page = 0,
  28.     row = 0,
  29.     col = 0; 
  30.  
  31. int activescreen, activeoffset;
  32.  
  33. int Initialized = 0;        /* are all the critical pointers set? */ 
  34.  
  35. char far *hidescreen;       /* pointer to invisible screen buffer */
  36.  
  37. static union REGS old_vid;
  38. static union REGS __xy;     /* holds machine cursor address for set */
  39.  
  40. int lm = TOPX,
  41.     rm = BTMX,
  42.     tm = TOPY,
  43.     bm = BTMY;              /* default window margins */
  44.  
  45. int synchronized = 1;       /* default to hard & soft cursors alike */
  46.  
  47.  
  48. /*
  49. ** Initialize, Deinitialize
  50. */
  51.  
  52. static void init_criticals( int mode )
  53. {
  54.     int i;
  55.     union REGS rx;
  56.  
  57.     if ( (hidescreen  = (char far *) _fmalloc(SCRLIM)) == 0L ) 
  58.            exit(27);
  59.  
  60.     video.mode = 7;                /* assume monochrome mode */
  61.     rasterh  = 12;                 /* assume monochrome cursor */
  62.     rasterl  = 13;
  63.  
  64.     rx.h.ah = 15;                  /* read current video mode */
  65.     int86( 0x10, &rx, &old_vid );
  66.     vid_page = old_vid.h.bh;
  67.     video.mode = old_vid.h.al;     /* 7 means we found monochrome hardware */
  68.  
  69.  
  70.     if (mode == 0)             /* request to stay in current mode? */
  71.         mode = video.mode;  
  72.  
  73.     /* in any case, allow only mono mode 7, or cga modes 2 or 3 */
  74.  
  75.     if (video.mode != 7)       /* is hardware a color/graphics adapter? */
  76.     {
  77.        if ( mode == 3 )        /* asking for color?  set it up! */
  78.        {
  79.           for (i = 0; i < 16; i++) 
  80.               vid[i] = i;                      /* set color defaults */
  81.           vid[0]  = 0x17 | 0x08;               /* set normal         */
  82.           vid[1]  = 0x06 | 0x08;               /*  "  bold           */
  83.           vid[2]  = 0x71 | 0x08;               /*  "  emphasis       */
  84.           vid[3]  = 0x47 | 0x08 | 0x80;        /*  "  attention      */
  85.        }
  86.        else 
  87.        {
  88.           mode = 2;                 /* only modes 2 and 3 are allowed, here */
  89.           for (i = 4; i < 16; i++)  /* all else defaults to normal */
  90.               vid[i] = vid[0];
  91.        }
  92.        rasterh = 6;               /* cga default cursor raster lines */
  93.        rasterl = 7;
  94.        if (video.mode != mode)      /* not already in the requested mode? */
  95.        {
  96.           rx.h.ah = 0;            /* if not, set requested mode */
  97.           rx.h.al = mode;
  98.           int86( 0x10, &rx, &rx );
  99.        }
  100.        rx.h.ah = 15;              /* read current mode again */
  101.        int86( 0x10, &rx, &rx );
  102.        video.mode = rx.h.al;
  103.     }
  104.  
  105.     Initialized = 1;              /* we are, basically, but...  */
  106.     vid_attr = vid[0];            /* and ensure vid_attr is set */
  107. }
  108.  
  109.  
  110.  
  111.  
  112. /* Vid_Init() - This is a "MUST CALL", but if the various routines which
  113. **              depend on finding initialized values and pointers find the
  114. **              Initialized flag set to zero, they will take it on themselves
  115. **              to call vid_init(0).  Any argument to vid_init is valid, but
  116. **              mode 7 is set if the monochrome adapter is in the system, and
  117. **              only modes 2 or 3 are set if the cga card is found.  The 
  118. **              0 argument requests that a valid current mode not be changed;
  119. **              this prevents the firmware from clearing the screen, if it's
  120. **              not absolutely necessary.  Vid_init() will always select the
  121. **              visible screen, and synchronize the soft & machine cursors.
  122. **              Also, selects appropriate default cursor size; cga and mono
  123. **              have different cursors.
  124. */
  125.  
  126. void vid_init( int mode )
  127. {
  128.     char far *p;
  129.     union REGS x;
  130.  
  131.     init_criticals( mode );      /* sets initialized flag on exit */
  132.  
  133.     /* now that the caller's requested mode is set, we must initialize
  134.        the nine low-level MSJ functions along with the video structure
  135.        */
  136.     MSJ_GetVideoParms( &video );
  137.  
  138.     /* save startup screen, blank if init_criticals changed the video mode */
  139.     setscreen(1);  /* ensure activescreen is set (still a do nothing?) */
  140.     p = savescreen(&x); /* snowfree here too, please! */
  141.     movedata( ptrseg(p), ptrofs(p), ptrseg(hidescreen), ptrofs(hidescreen), SCRLIM );
  142.     _ffree(p);
  143.  
  144.     __xy.h.ah = 3;            /* read machine cursor into dh, dl */
  145.     __xy.h.bh = 0;
  146.     int86( 0x10, &__xy, &__xy );
  147.     row = __xy.h.dh;
  148.     col = __xy.h.dl;
  149.     synchronized = 1;
  150. }                              
  151.  
  152.  
  153.  
  154.  
  155. void vid_exit( void )
  156. {
  157.      if (Initialized)
  158.      {
  159.           if (old_vid.h.al != video.mode)
  160.           {
  161.                old_vid.h.ah = 0;
  162.                int86( 0x10, &old_vid, &old_vid );
  163.           }
  164.  
  165.           __xy.h.ah = 1;
  166.           int86( 0x10, &__xy, &__xy ); /* old cursor size */
  167.           __xy.h.ah = 2;
  168.           int86( 0x10, &__xy, &__xy);  /* old cursor loc */
  169.  
  170.           swapscreen(1);
  171.           _ffree(hidescreen);
  172.      }
  173.      setcursize( rasterh, rasterl );
  174.      Initialized = 0;  /* we're NOT initialized any more! */
  175. }
  176.  
  177.  
  178.